#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244853;
typedef long long LL;
const int N = 1100 * 5;

int x1,x2,a1,a2,b1,b2;

int ans = 0x3f3f3f3f3f3f3f3f;
int res1 = 0x3f3f3f3f,res2 = 0x3f3f3f3f;
int func(int x,int y)
{
    if(x > b1 || x < a1) return 0x3f3f3f3f3f3f3f3f;
    if(x == a1)
    {
        if(y < a2) return 0x3f3f3f3f3f3f3f3f;
    }
    if(x == b1)
    {
        if(y > b2) return 0x3f3f3f3f3f3f3f3f;
    }
    int ans1 = 0;
    int mina = min(abs(y - x2),60 - abs(y - x2));
    ans1 += (3600 / 60) * mina;
    int c1 = 3600 / 12 * x + 5 * y;
    int c2 = 3600 / 12 * x1 + 5 * x2;
    ans1 += min(abs(c1 - c2), 3600 - abs(c1 - c2));
    return ans1;
}

void fz(int x,int y)
{
    if(func(x,y) <= ans)
    {
        if(func(x,y) < ans)
        {
            ans = func(x,y);
            res1 = x;
            res2 = y;
        }
        else
        {
            if(x < res1)
            {
                res1 = x;
                res2 = y;
            }
            else if(x == res1 && y < res2)
            {
                res2 = y;
            }
        }
    }
}
void solve()
{  
    ans = 0x3f3f3f3f3f3f3f3f;
    res1 = 0x3f3f3f3f,res2 = 0x3f3f3f3f;
    cin >> x1 >> x2 >> a1 >> a2 >> b1 >> b2;
    for(int i = 0; i <= 11; i ++)
    {
        for(int j = 0; j <= 59; j ++)
        {
            fz(i,j);
        }
    }
    cout << res1 << " " << res2 << endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/*

 */